// 给你一个字符串 s，找到 s 中最长的回文子串。
var longestPalindrome = function (s) {
  let str = ''
  for (var i = 0; i < s.length; i++) {
    // 奇数的情况
    let left = i
    let right = i
    while (left >= 0 && right < s.length && s[left] == s[right]) {
      left--
      right++
    }
    if (right - left - 1 > str.length) {
      str = s.substring(left + 1, right)
    }
    // 偶数的情况
    left = i
    right = i + 1
    while (left >= 0 && right < s.length && s[left] == s[right]) {
      left--
      right++
    }
    if (right - left - 1 > str.length) {
      str = s.substring(left + 1, right)
    }
  }
  return str
}
console.log(longestPalindrome('cbbd'));